<?php

class Model_User extends \Orm\Model
{
	protected static $_properties = array(
		'id',
		'username',
		'password',
		'group',
		'email',
		'last_login',
		'login_hash',
		'profile_fields',
		'created_at',//'created_at', để như thế này lúc dùng creat_auth ko bị lỗi.
		'updated',//dupdated_at',
                'status', // two rows belows is not default
                'deleted',
//              'id', 
//        'post_title' => array( //column name
//            'data_type' => 'string',
//            'label' => 'Post Title', //label for the input field
//            'validation' => array('required', 'max_length'=>array(100), 'min_length'=>array(10)) //validation rules
//        ),
//        'post_content' => array( 
//            'data_type' => 'string',
//            'label' => 'Post Content',
//            'validation' => array('required')
//        ),
//        'author_name' => array( 
//            'data_type' => 'string',
//            'label' => 'Author Name',
//            'validation' =>  array('required', 'max_length'=>array(65), 'min_length'=>array(2))
//        ),
//        'author_email' => array( 
//            'data_type' => 'string',
//            'label' => 'Author Email',
//            'validation' =>  array('required', 'valid_email')
//        ),
//        'author_website' => array( 
//            'data_type' => 'string',
//            'label' => 'Author Website',
//            'validation' =>  array('required', 'valid_url', 'max_length'=>array(60))
//        ),
//        'post_status' => array(
//            'data_type' => 'string',
//            'label' => 'Post Status',
//            'validation' => array('required'),
//            'form' => array('type' => 'select', 'options' => array(1=>'Published', 2=>'Draft')),
//        )
	);

	protected static $_observers = array(
		'Orm\Observer_CreatedAt' => array(
			'events' => array('before_insert'),
			'mysql_timestamp' => false,
		),
		'Orm\Observer_UpdatedAt' => array(
			'events' => array('before_update'),
			'mysql_timestamp' => false,
		),
	);
	protected static $_table_name = 'users';
        public static function get_validation_register(Validation $val)
    {
        $val->add_callable(new MyRules()); //thêm rules unique của mình
        $val->add_field('username', 'Username', 'required|trim|min_length[3]|max_length[20]|valid_string[alpha,lowercase,numeric]|unique[users.username]');
        $val->add_field('password', 'Password', 'required|trim|min_length[3]|max_length[20]');
        $val->add_field('password_confirm', 'Password confirm', 'required|trim|match_field[password]');
        $val->add_field('email', 'Email address', 'required|trim|valid_email|unique[users.email]');
        return $val;
    }
        public static function get_validation_edit_account(Validation $val)
    {
        $val->add_callable(new MyRules()); //thêm rules unique của mình
        $val->add_field('username', 'Username', 'required|trim|min_length[3]|max_length[20]|valid_string[alpha,lowercase,numeric]');
        $val->add_field('password', 'Password', 'required|trim|min_length[3]|max_length[20]');
        $val->add_field('email', 'Email address', 'required|trim|valid_email');
        return $val;
    }
     public static function get_validation_edit_password(Validation $val)
    {
        $val->add_callable(new MyRules()); //thêm rules unique của mình
        $val->add_field('oldpassword', 'Oldpassword', 'required|trim|min_length[3]|max_length[20]');
        $val->add_field('password', 'Password', 'required|trim|min_length[3]|max_length[20]');
        $val->add_field('password_confirm', 'Password confirm', 'required|trim|match_field[password]');
        return $val;
       
    }
    
    

}
